package com.his.invdrug.controller;

import com.his.config.annotation.CurrentUser;
import com.his.invdrug.entity.InvDrugHeader_Detailed;
import com.his.invdrug.service.InvDrugHeaderServcie;
import com.his.invdrug.vo.InvDrugHeaderSearchVo;
import com.his.invdrug.vo.InvDrugHeader_DetailedVo;
import com.his.login.entity.DictEmployee;
import com.xiao.common.controller.ResultBaseController;
import com.xiao.common.util.ResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 出入库控制类
 * @Author tansonglin
 * @Date 2020/3/20
 */
@RestController
@RequestMapping(value="/api/inv_drug_header")
public class InvDrugHeaderController extends ResultBaseController {
    private  final Logger logger = (Logger) LoggerFactory.getLogger(this.getClass());

    @Autowired
    private InvDrugHeaderServcie invDrugHeaderServcie;
    /**
     * 查询库单数据-用作首页展示
     */
    @PostMapping(value="/query_for_mainshow.do")
    public ResultUtil queryDrugHeaderForMainShow(@CurrentUser DictEmployee dictEmployee, @RequestBody InvDrugHeaderSearchVo invDrugHeaderSearchVo){
        try{
            List<InvDrugHeader_Detailed> invDrugHeaderDetaileds=invDrugHeaderServcie.queryDrugHeaderForMainShow(dictEmployee,invDrugHeaderSearchVo);
            return this.success("成功",invDrugHeaderDetaileds);
        }catch(Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }
    /**
     * 查询库单详细信息
     */
    @GetMapping(value="/query_detailed.do")
    public ResultUtil queryDetailed(@CurrentUser DictEmployee dictEmployee,String drugHeaderID){
        try{
            InvDrugHeader_Detailed invDrugHeaderDetailed=invDrugHeaderServcie.queryDetailed(drugHeaderID);
            return this.success("成功",invDrugHeaderDetailed);
        }catch(Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }
    /**
     *添加库单
     */
    @PostMapping(value="/insert.do")
    public ResultUtil insetDeugHeader(@CurrentUser DictEmployee dictEmployee,@RequestBody InvDrugHeader_DetailedVo invDrugHeaderDetailedVo){
        try{
            invDrugHeaderServcie.insertDrugHeader(dictEmployee,invDrugHeaderDetailedVo);
            return this.success("成功",null);
        }catch(Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }
    /**
     * 修改库单
     */
    @PostMapping(value="/update.do")
    public ResultUtil updateDeugHeader(@CurrentUser DictEmployee dictEmployee, @RequestBody InvDrugHeader_DetailedVo invDrugHeaderDetailedVo){
        try{
            invDrugHeaderServcie.updateDrugHeader(dictEmployee,invDrugHeaderDetailedVo);
            return this.success("成功",null);
        }catch(Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }
    /**
     * 审核
     */
    @GetMapping(value="/examine.do")
    public ResultUtil examine(@CurrentUser DictEmployee dictEmployee, String invporpID){
        try{
            invDrugHeaderServcie.examine(dictEmployee,invporpID);
            return this.success("成功",null);
        }catch(Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }
    /**
     * 取消审核
     */
    @GetMapping(value="/cancel_examine.do")
    public ResultUtil cancelExamine(@CurrentUser DictEmployee dictEmployee, String invporpID){
        try{
            invDrugHeaderServcie.cancelExamine(dictEmployee,invporpID);
            return this.success("成功",null);
        }catch(Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }
}
